<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: popup_coupon_help.php 191 2013-09-22 07:57:32Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 191 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-22 07:57:32 +0000 (Sun, 22 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

require ('includes/application_top.php');
require_once (DIR_FS_INC.'inc.date_short.php');

$smarty = new Smarty;

include('includes/header.php');

$coupon = $db->db_query("SELECT * FROM ".TABLE_COUPONS." WHERE coupon_id = '".(int)$_GET['cID']."'");

$coupon_desc = $db->db_query("SELECT * FROM ".TABLE_COUPONS_DESCRIPTION." WHERE coupon_id = '".(int)$_GET['cID']."' AND language_id = '".$_SESSION['languages_id']."'");

$text_coupon_help = TEXT_COUPON_HELP_HEADER;
$text_coupon_help .= sprintf(TEXT_COUPON_HELP_NAME, $coupon_desc->fields['coupon_name']);

if (not_null($coupon_desc->fields['coupon_description']))
	$text_coupon_help .= sprintf(TEXT_COUPON_HELP_DESC, $coupon_desc->fields['coupon_description']);
	
$coupon_amount = $coupon->fields['coupon_amount'];
switch ($coupon->fields['coupon_type']) {
	case 'F' :
		$text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, $price->format($coupon->fields['coupon_amount'], true));
		break;
		
	case 'P' :
		$text_coupon_help .= sprintf(TEXT_COUPON_HELP_FIXED, number_format($coupon->fields['coupon_amount'], 2).'%');
		break;
		
	case 'S' :
		$text_coupon_help .= TEXT_COUPON_HELP_FREESHIP;
		break;
}

if ($coupon->fields['coupon_minimum_order'] > 0)
	$text_coupon_help .= sprintf(TEXT_COUPON_HELP_MINORDER, $price->format($coupon->fields['coupon_minimum_order'], true));
	
$text_coupon_help .= sprintf(TEXT_COUPON_HELP_DATE, date_short($coupon->fields['coupon_start_date']), date_short($coupon->fields['coupon_expire_date']));
$text_coupon_help .= '<b>'.TEXT_COUPON_HELP_RESTRICT.'</b>';
$text_coupon_help .= '<br /><br />'.TEXT_COUPON_HELP_CATEGORIES;

$get_get = $db->db_query("SELECT restrict_to_categories from ".TABLE_COUPONS." WHERE coupon_id = '".(int)$_GET['cID']."'");

$cat_ids = explode(",", $get_result->fields['restrict_to_categories']);
for ($i = 0; $i < count($cat_ids); $i ++) {
	$row = $db->db_query("SELECT 
								* 
							FROM 
								".TABLE_CATEGORIES." c, 
								".TABLE_CATEGORIES_DESCRIPTION." cd 
							WHERE 
								c.categories_id = cd.categories_id 
							AND 
								cd.language_id = '".$_SESSION['languages_id']."' 
							AND 
								c.categories_id='".$cat_ids[$i]."'");
	if($row->_numOfRows)
		$cats .= $row->fields["categories_name"].'<br />';
}
if ($cats == '')
	$cats = '<br />NONE';
	
$text_coupon_help .= $cats;
$text_coupon_help .= '<br /><br />'.TEXT_COUPON_HELP_PRODUCTS;

$get_result = $db->db_query("SELECT restrict_to_products FROM ".TABLE_COUPONS."  WHERE coupon_id='".(int)$_GET['cID']."'");

$pr_ids = explode(",", $get_result->fields['restrict_to_products']);
for ($i = 0; $i < count($pr_ids); $i ++) {
	$row = $db->db_query("SELECT 
								* 
							FROM 
								".TABLE_PRODUCTS." p, 
								".TABLE_PRODUCTS_DESCRIPTION." pd 
							WHERE 
								p.products_id = pd.products_id 
							AND 
								pd.language_id = '".$_SESSION['languages_id']."'
							AND 
								p.products_id = '".$pr_ids[$i]."'");
									
	if($row->_numOfRows)
		$prods .= '<br />'.$row->fields["products_name"];
}
if($prods == '')
	$prods = '<br />NONE';
	
$text_coupon_help .= $prods;

$smarty->assign('TEXT_HELP', $text_coupon_help);
$smarty->assign('link_close', 'javascript:window.close()');
$smarty->assign('language', $_SESSION['language']);

$smarty->caching = false;
$smarty->display(CURRENT_TEMPLATE.'/module/popup_coupon_help.html');
include ('includes/application_bottom.php');
?>